#pragma once
#include "COM_h.h"
#include "Header.hpp"

class CAnimals : public IDog, public ICat, public IPig, public ISupportErrorInfo
{
private:
    unsigned int m_nCnt;

public:
    CAnimals();
    ~CAnimals();

public:
    BEGIN_INTERFACE_TABLE()
        INTERFACE_TABLE_ENTRY(CAnimals, IDog)
        INTERFACE_TABLE_ENTRY(CAnimals, ICat)
        INTERFACE_TABLE_ENTRY(CAnimals, IPig)
        INTERFACE_TABLE_ENTRY(CAnimals, ISupportErrorInfo)
    END_INTERFACE_TABLE()

    DECLARE_DEFAULT_INTERFACE(CAnimals);

public:
    virtual HRESULT STDMETHODCALLTYPE Woof(IN const unsigned char* lpString);
    virtual HRESULT STDMETHODCALLTYPE Meow(IN const unsigned char* lpString);
    virtual HRESULT STDMETHODCALLTYPE Oink(IN const unsigned char* lpString);

    virtual HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo(IN REFIID riid);
};


class CAnimalsFactory : IClassFactory
{
private:
    unsigned int m_nLockTick;

public:
    CAnimalsFactory();
    ~CAnimalsFactory();

public:
    inline unsigned int GetReferences() const { return m_nLockTick; }

public:
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
    virtual ULONG STDMETHODCALLTYPE AddRef();
    virtual ULONG STDMETHODCALLTYPE Release();

    virtual HRESULT STDMETHODCALLTYPE CreateInstance(
        IN OPTIONAL IUnknown* pUnkOuter,
        IN REFIID riid,
        OUT void** ppvObject
    );

    virtual HRESULT STDMETHODCALLTYPE LockServer(IN BOOL fLock);
};

EXTERN_C const GUID CLSID_ANIMALS;
